package com.apress.prospringintegration.messageflow.filter;

import com.apress.prospringintegration.messageflow.domain.MarketItem;
import com.apress.prospringintegration.messageflow.domain.MarketItemCreator;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.support.MessageBuilder;

/**
 * Created by IntelliJ IDEA.
 * User: wenwei
 * Date: 4/18/11
 * Time: 2:26 PM
 * To change this template use File | Settings | File Templates.
 */
public class MainItemFilter {
    public static void main(String[] args) throws Exception {
        ApplicationContext context = new ClassPathXmlApplicationContext("filter-item.xml");
        MessageChannel channel =
        context.getBean("marketItemChannel", MessageChannel.class);
        MarketItemCreator marketItemCreator =
        context.getBean("marketItemCreator", MarketItemCreator.class);
        for (MarketItem marketItem : marketItemCreator.getMarketItems()) {
            channel.send(MessageBuilder.withPayload(marketItem)
                .setHeader("ITEM_TYPE", marketItem.getType()).build());
        }
    }
}
